<%@ page import="hp.com.entity.Users" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<%
    String path = request.getContextPath();
    request.setAttribute("path",path);
    Users userSession =(Users) request.getSession().getAttribute("userSession");
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<link type="text/css" rel="stylesheet" href="${path}/jbs/css/style.css" />
    <script type="text/javascript" src="${path}/jbs/js/jquery-1.8.2.min.js"></script>
    <script type="text/javascript" src="${path}/jbs/js/menu.js"></script>
    <script type="application/javascript">
        window.onload=function(){
            var finalPrice= document.getElementById("totalPrice");
            finalPrice.innerHTML='计算中...';
            checkPriceAll();
        }
        function checkPriceAll(){
            var set=jQuery("*[id^='price_']");
            var finalPrice= document.getElementById("totalPrice")
            var total =parseFloat(parseFloat("0").toFixed(2));
            finalPrice.innerHTML='计算中...';
            set.each(function (index,item){
                total=total+parseFloat(parseFloat(item.textContent).toFixed(2));
                }
            )
            finalPrice.innerHTML='¥'+total.toFixed(2);
        }
        function cartAmountUpdateHandWrite(thisElement,dataId,priceId){
            var price = document.getElementById(priceId);
            var c= thisElement.value;
            jQuery.ajax({
                url: "${path}/CartPriceAjax",
                type:"post",
                data:{"dataId":dataId,"newAmount":c},
                dataType:"json",
                beforeStart:function(){},
                success:function(result){
                    price.innerHTML=result;
                },error:function (){
                    alert("ww");
                },complete:function (){
                    checkPriceAll()
                }
            })

        }
        function cartAddUpdate1(jia,dataId,priceElement) {
            var price = document.getElementById(priceElement);
            var c = jia.parent().find(".car_ipt").val();
            c = parseInt(c) + 1;
            jQuery.ajax({
                url: "${path}/CartPriceAjax",
                type:"post",
                data:{"dataId":dataId,"newAmount":c},
                dataType:"json",
                beforeStart:function(){},
                success:function(result){
                    jia.parent().find(".car_ipt").val(c);
                    price.innerHTML=result;
                },complete:function (){
                    checkPriceAll()
                }
            })
        }
        function cartMinusUpdate1(jia,dataId,priceElement) {
            var price = document.getElementById(priceElement);
            var c = jia.parent().find(".car_ipt").val();
            c = parseInt(c) - 1;
            if(parseInt(c)<parseInt("1")){
                c=1;
                return;
            }
            jQuery.ajax({
                url: "${path}/CartPriceAjax",
                type:"post",
                data:{"dataId":dataId,"newAmount":c},
                dataType:"json",
                beforeStart:function(){},
                success:function(result){
                    jia.parent().find(".car_ipt").val(c);
                    price.innerHTML=result;
                },complete:function (){
                    checkPriceAll()
                }
            })
        }
    </script>
	<script type="text/javascript" src="${path}/jbs/js/n_nav.js"></script>

    <script type="text/javascript" src="${path}/jbs/js/num.js">
    	let jq = jQuery.noConflict();
    </script>

    <script type="text/javascript" src="${path}/jbs/js/shade.js"></script>

    <link rel="icon" href="<%=path%>/jbs/images/ico.ico" type="image/x-icon">
<title>购物车-青鸟优选</title>
</head>
<body style="margin: 0;" >
<div class="soubg">
    <div class="sou">
        <span class="fr">
        	<span class="fl">
                <c:choose>
                    <c:when test="<%= userSession == null%>">

                        <a href="${path}/jbs/Login.jsp" style="color:#ff4e00;">登录</a>&nbsp;|&nbsp;
                        <a href="${path}/jbs/Regist.jsp" style="color:#ff4e00;">免费注册</a>&nbsp;&nbsp;
                    </c:when>
                    <c:otherwise>
                        <a href=""><%=userSession.getLoginname()%></a>&nbsp;|&nbsp;
                        <a href="#">我的订单</a>
                    </c:otherwise>
                </c:choose>
            </span>
        </span>
    </div>
</div>
<div class="top">
    <div class="logo"><a href="${patb}/Index"><img src="${path}/jbs/images/logo.png" /></a></div>
    <div class="search">
        <form>
            <input type="text" value="" class="s_ipt" />
            <input type="submit" value="搜索" class="s_btn" />
        </form>

    </div>
</div>
<!--End Header End-->
<div class="i_bg">
    <a name="showCart"></a>
    <div class="content mar_20" style="font-size: 50px;color: #02A4d9;font-weight: bold">
        购物车
    </div>

    <!--Begin 第一步：查看购物车 Begin -->
    <div class="content mar_20">
        <table border="0" class="car_tab" style="width:1200px; margin-bottom:50px;" cellspacing="0" cellpadding="0">
            <tr>
                <td class="car_th" width="490">商品名称</td>
                <td class="car_th" width="140">属性</td>
                <td class="car_th" width="150">购买数量</td>
                <td class="car_th" width="130">小计</td>
                <td class="car_th" width="150">操作</td>
            </tr>
            <c:forEach  items="${requestScope.Buy}" begin="0" end="${fn:length(requestScope.Buy)}" var="data" varStatus="i">
            <tr class="car_tr">
                <td>
                    <div class="c_s_img"><img src="${data.pic}" width="73" height="73" /></div>
                    ${data.fullname}
                </td>
                <td align="center">${data.suk}</td>
                <td align="center">
                    <div class="c_num">
                        <input type="button" value="" onclick="cartMinusUpdate1(jq(this),${data.dataId},'price_${i.index}');" class="car_btn_1" />
                        <input type="text" value="${data.itemNumber}" name="" class="car_ipt" onblur="cartAmountUpdateHandWrite(this,${data.dataId},'price_${i.index}')"/>
                        <input type="button" value="" onclick="cartAddUpdate1(jq(this),${data.dataId},'price_${i.index}');" class="car_btn_2" />
                    </div>
                </td>
                <td align="center"  style="color: #02A4F8;">￥<span id="price_${i.index}">${data.price}</span></td>
                <td align="center"><a onclick="OpenDiv('removeCardMessage','fadeBlack',${data.dataId})">删除</a>&nbsp;
            </tr>
            </c:forEach>
            <tr height="70">
                <td colspan="6" style="font-family:'Microsoft YaHei'; border-bottom:0;">
                    <span class="fr">商品总价：<b style="font-size:22px; color: #02A4F8;" id="totalPrice"></b></span>
                </td>
            </tr>
            <tr valign="top" height="150">
                <td colspan="6" align="right" style="border: none">
                    <a href="#" onclick="window.history.back()"><span class="button_r">继续购物</span></a>&nbsp;<a href="${path}/Cart_Two"><span class="button_rc">结算购物车</span></a>
                </td>
            </tr>
        </table>

    </div>
    <!--End 第一步：查看购物车 End-->


    <!--Begin 弹出层-删除商品 Begin-->
    <div id="fade" class="black_overlay"></div>
    <div id="ShowDiv" class="white_content">
        <div class="white_d">
            <div class="notice_t">
                <span class="fr" style="margin-top:10px; cursor:pointer;" onclick="CloseDiv('MyDiv','fade')"><img src="${path}/jbs/images/close.gif" /></span>
            </div>
            <div class="notice_c">

                <table border="0" align="center" style="font-size:16px;" cellspacing="0" cellpadding="0">
                    <tr valign="top">
                        <td>您确定要把该商品移除购物车吗？</td>
                    </tr>
                    <tr height="50" valign="bottom">
                        <td><a href="#" class="button_rc" id="confirmButton" style="float: left">确定</a><a onClick="CloseDiv('MyDiv','fade')" class="button_r" style="float: right">取消</a></td>
                    </tr>
                </table>

            </div>
        </div>
    </div>
    <!--End 弹出层-删除商品 End-->
    <!--Begin Footer Begin -->
    <div class="b_btm_bg bg_color">
        <div class="b_btm">
            <table border="0" style="width:210px; height:62px; float:left; margin-left:75px; margin-top:30px;" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="72"><img src="${path}/jbs/images/b1.png" width="62" height="62" /></td>
                    <td><h2>正品保障</h2>正品行货  放心购买</td>
                </tr>
            </table>
            <table border="0" style="width:210px; height:62px; float:left; margin-left:75px; margin-top:30px;" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="72"><img src="${path}/jbs/images/b2.png" width="62" height="62" /></td>
                    <td><h2>满38包邮</h2>满38包邮 免运费</td>
                </tr>
            </table>
            <table border="0" style="width:210px; height:62px; float:left; margin-left:75px; margin-top:30px;" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="72"><img src="${path}/jbs/images/b3.png" width="62" height="62" /></td>
                    <td><h2>天天低价</h2>天天低价 畅选无忧</td>
                </tr>
            </table>
            <table border="0" style="width:210px; height:62px; float:left; margin-left:75px; margin-top:30px;" cellspacing="0" cellpadding="0">
                <tr>
                    <td width="72"><img src="${path}/jbs/images/b4.png" width="62" height="62" /></td>
                    <td><h2>准时送达</h2>收货时间由你做主</td>
                </tr>
            </table>
        </div>
    </div>
    <div class="btmbg">
        <div class="btm">
            <a href="https://beian.miit.gov.cn">备案/许可证编号：鄂ICP备20008779号-1</a> <br />本站仅供个人学习实践，无实际购买功能
        </div>
    </div>
    <!--End Footer End -->
</div>
</body>


<script src="${path}/jbs/js/zh_CN.js"></script>
</html>
